// pages/mytrain/ruleDesImg/ruleDesImg.js
import * as echarts from '../../../ec-canvas/echarts.min';
var utils = require('../../../utils/util.js');
var httpUrl = getApp().globalData.httpUrl;
let chart = null;

function initChart(canvas, width, height) {
    chart = echarts.init(canvas, null, {
        width: width,
        height: height
    });
    canvas.setChart(chart);
 
}
Page({

    /**
     * 页面的初始数据
     */
    data: {
        ec: {
            onInit: initChart
        },
        date:"",
        typeid:"",
        member_id:""
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        var that = this;
        if (options.scene) {
            var scene = decodeURIComponent(options.scene);
            var arrPara = scene.split("@");
             var arr = [];
            for (var i in arrPara) {
                var member_id = arrPara[0];
                var date = arrPara[1];
                var type = arrPara[2];
            }
            console.log("member_id" + member_id + "date" + date + "type" + type);
            that.setData({
                member_id:member_id,
                date:date,
                typeid:type
            }) 
        } else {
            that.setData({
                member_id:"",
                date: options.date,
                typeid: options.typeid,
                name: options.name,
            })
        }
        that.listTap();
    },
    listTap:function(e){
        var that=this;
          utils.http(httpUrl + "/mobile/member/train_report", {
            date:that.data.date ,
              typeid: that.data.typeid,
            member_id:that.data.member_id
        }, function(res) {
            console.log(res);
            if (res.state == 1) {
                var ata_arr = res.datas.ata_arr;
                var day_arr = res.datas.day_arr;
                var option = {
                    title: {
                        text: '完成（个/秒）',
                        textStyle: {
                            fontSize: 10
                        },
                        left: "16",
                        top: "15"
                    },
                    tooltip: {
                        trigger: 'axis'
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },

                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        data: day_arr
                    },
                    yAxis: {
                        type: 'value'
                    },
                    series: [{
                        name: '邮件营销',
                        type: 'line',
                        stack: '总量',
                        data: ata_arr,
                        itemStyle: {
                            normal: {
                                color: '#61c7f8'
                            }
                        }
                    }]
                };

                chart.setOption(option);
            } else {
               // utils.message(res.datas);
            }
        })

    },
    //进入分享页面
    oNruleDescriptionTap: function(e) {
        var that=this;
        wx.navigateTo({
            url: "../generateReports/generateReports?typeid="+that.data.typeid+"&date="+that.data.date
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {
        setTimeout(function() {
            // 获取 chart 实例的方式
            // console.log(chart)
        }, 2000);
    }
})